Since the fully connected topology of particle swarm algorithm has low convergence precision and easily falls into local extremum, an approach for automatically generating structural test data based on a hybrid particle swarm algorithm named HPSO (Hybrid Particle Swarm Optimization) was proposed. Firstly, under the premise of global convergence, the population which lacked of diversity used fixed-length ring topology to replace the fully connected one. Secondly, the roulette wheel method was introduced to select the candidate solutions and update the location information and velocity information. Lastly, for controlling and directing the particles to escape from local minimum, the conditions of tabu search algorithm were introduced too. The result of experiment shows that HPSO has a better performance than the Basic Particle Swarm Optimization (BPSO) in population diversity. And HPSO exhibited superiority in search success rate and path coverage in contract with combination method of Genetic Algorithm and Particle Swarm Optimization algorithm named GA-PSO in test data generation, while the average time-consuming is not much different from BPSO.